package com.two.screen.water.balance.widget.dialog

import android.app.Dialog
import android.content.Context
import com.two.screen.water.balance.R


class GuaDanDialog(context: Context) : Dialog(context, R.style.ChooseDialog) {
//
//    private var mTimeRcy: RecyclerView? = null
//    private var mOrderRcy: RecyclerView? = null
//    private var mTimeAdapter: TimeAdapter? = null
//    private var mOrderAdapter: OrderAdapter? = null
//    private var mOnGuaDanDialogListener: OnGuaDanDialogListener? = null
//    private var dialog_tv1: TextView? = null
//    private var dialog_tv2: TextView? = null
//    private var dialog_tv3: TextView? = null
//    private var dialog_tv4: TextView? = null
//    private var dialog_tv5: TextView? = null
//
//    override fun onCreate(savedInstanceState: Bundle?) {
//        super.onCreate(savedInstanceState)
//        setContentView(R.layout.dialog_gua_dan)
//        this.setCanceledOnTouchOutside(false)
//
//        val window = window
//        if (window != null) {
//            val attributes = window.attributes
//            attributes.width = App.screenWidth
//            window.attributes = attributes
//            window.setGravity(Gravity.CENTER)
//        }
//        mTimeRcy = findViewById(R.id.mTimeRcy)
//        mOrderRcy = findViewById(R.id.mOrderRcy)
//        dialog_tv1 = findViewById(R.id.dialog_tv1)
//        dialog_tv2 = findViewById(R.id.dialog_tv2)
//        dialog_tv3 = findViewById(R.id.dialog_tv3)
//        dialog_tv4 = findViewById(R.id.dialog_tv4)
//        dialog_tv5 = findViewById(R.id.dialog_tv5)
//        initTimeRcy()
//        initOrderRcy()
//
////        inputEt = findViewById(R.id.dialog_et)
////        findViewById<ImageView>(R.id.mShuaKaBgIv).apply {
////            ImageManger.setBgImageFitCenter(context, Urls.VipCenterInputBG_URL, this)
////        }
////        findViewById<View>(R.id.dialog_iv).apply {
////            setOnClickListener {
////                dismiss()
////            }
////        }
//        findViewById<View>(R.id.mCloseIv).apply {
//            setOnClickListener {
//                dismiss()
//            }
//        }
////        findViewById<View>(R.id.dialog_root).apply {
////            setOnClickListener {
////                dismiss()
////            }
////        }
////        findViewById<View>(R.id.dialog_tv5).apply {
////            RxView.clicks(this)
////                .throttleFirst(1, TimeUnit.SECONDS)
////                .subscribe {
////                    mOnGuaDanDialogListener?.onApplyOrder(handOrderBean)
////                    dismiss()
////                }
////        }
//    }
//
//    private fun initTimeRcy() {
//        (mTimeRcy?.itemAnimator as SimpleItemAnimator).supportsChangeAnimations = false //去闪烁
//        mTimeRcy?.addItemDecoration(
//            DividerItemDecoration(context, DividerItemDecoration.HORIZONTAL_LIST, 1, ContextCompat.getColor(App.context!!, R.color.line_color), false)
//        )
//        mTimeAdapter = TimeAdapter()
//        mTimeRcy?.layoutManager = LinearLayoutManager(context)
//        mTimeRcy?.adapter = mTimeAdapter
//        mTimeAdapter?.bindToRecyclerView(mTimeRcy)
//        mTimeAdapter?.setEmptyView(R.layout.layout_status_layout_manager_empty1)
//        //mTimeAdapter?.setNewData(mutableListOf(HandOrderBean(), HandOrderBean(), HandOrderBean(), HandOrderBean(), HandOrderBean(), HandOrderBean(), HandOrderBean()))
//    }
//
//    private fun initOrderRcy() {
//        (mOrderRcy?.itemAnimator as SimpleItemAnimator).supportsChangeAnimations = false //去闪烁
//        mOrderRcy?.addItemDecoration(
//            DividerItemDecoration(context, DividerItemDecoration.HORIZONTAL_LIST, 1, ContextCompat.getColor(App.context!!, R.color.line_color), true)
//        )
//        mOrderAdapter = OrderAdapter()
//        mOrderRcy?.layoutManager = LinearLayoutManager(context)
//        mOrderRcy?.adapter = mOrderAdapter
//        mOrderAdapter?.bindToRecyclerView(mOrderRcy)
//        mOrderAdapter?.setEmptyView(R.layout.layout_status_layout_manager_empty1)
//        //mOrderAdapter?.setNewData(mutableListOf(FoodsBean(), HandOrderBean(), HandOrderBean(), HandOrderBean(), HandOrderBean(), HandOrderBean(), HandOrderBean()))
//    }
//
//    inner class TimeAdapter : BaseQuickAdapter<HandOrderBean, BaseViewHolder>(R.layout.item_dialog_time, null) {
//        override fun convert(helper: BaseViewHolder, item: HandOrderBean) {
//            (helper.itemView as TextView).apply {
//                text = item.add_time_text
//                if (item.isSelected) {
//                    setBackgroundColor(CommUtils.getColor(R.color.f6))
//                    setTextColor(CommUtils.getColor(R.color.blue_0084ff))
//                } else {
//                    setBackgroundColor(CommUtils.getColor(R.color.eaeaea))
//                    setTextColor(CommUtils.getColor(R.color.six8))
//                }
//                RxView.clicks(this)
//                    .throttleFirst(1, TimeUnit.SECONDS)
//                    .subscribe {
//                        mData.forEach { it.isSelected = false }
//                        item.isSelected = true
//                        notifyDataSetChanged()
//                        updateOrderInfo(item)
//                    }
//            }
//        }
//    }
//
//    @SuppressLint("CheckResult")
//    private fun updateOrderInfo(handOrderBean: HandOrderBean?) {
//        dialog_tv1?.text = handOrderBean?.order_sn ?: "暂无"
//        dialog_tv2?.text = handOrderBean?.add_time_text ?: "暂无"
//        dialog_tv3?.text = "￥".plus(handOrderBean?.total_price ?: "0.00")
//        dialog_tv4?.let {
//            RxView.clicks(it)
//                .throttleFirst(1, TimeUnit.SECONDS)
//                .subscribe {
//                    if (handOrderBean != null) {
//                        App.mDaoSession?.handOrderBeanDao?.deleteInTx(handOrderBean)
//                        updateTimeOrder()
//                    }
//                }
//        }
//        dialog_tv5?.let {
//            RxView.clicks(it)
//                .throttleFirst(1, TimeUnit.SECONDS)
//                .subscribe {
//                    if (handOrderBean != null) {
//                        mOnGuaDanDialogListener?.onApplyOrder(handOrderBean)
//                        dismiss()
//                    }
//                }
//        }
//        CommUtils.println("GuaDanDialog:", "${handOrderBean?.goodsList?.size ?: 0}")
//        mOrderAdapter?.setNewData(handOrderBean?.goodsList)
//    }
//
//    inner class OrderAdapter : BaseQuickAdapter<ProductBean, BaseViewHolder>(R.layout.item_dialog_order, null) {
//        override fun convert(helper: BaseViewHolder, item: ProductBean) {
//            helper
//                .setText(R.id.item_tv1, item.product_name)
//                .setText(R.id.item_tv2, item.sale_price)
//                .setText(R.id.item_tv3, item.weight)
//                .setText(R.id.item_tv4, item.price_sub_total)
//        }
//    }
//
//    fun setOnGuaDanDialogListener(l: OnGuaDanDialogListener) {
//        mOnGuaDanDialogListener = l
//    }
//
//    override fun show() {
//        super.show()
//        //TODO:查询表。查最近50条，后期优化分页。
//        updateTimeOrder()
//    }
//
//    private fun updateTimeOrder() {
//
//        var list = App.mDaoMaster?.newSession()?.queryBuilder(HandOrderBean::class.java)
//            // ?.where(OrderBeanDao.Properties.Test_result.notEq(0))   //结果,0:未检测，1:检测成功;2:检测不合格
//            //?.where(CarInfoBeanDao.Properties.Upload_status.notEq(1))  //上传状态。0:未上传，1:上传成功
//            //?.where(CarInfoBeanDao.Properties.Upload_status.eq(0))
//            //?.where(JlyBeanDao.Properties.UploadTimes.le(10))//小于或等于
//            ?.orderDesc(HandOrderBeanDao.Properties.LocalOrderId)
//            ?.offset(0)?.limit(50)?.list()
//        list?.forEach {
//            it.isSelected = false
//            CommUtils.println("GuaDanDialog:", CommUtils.gson.toJson(it))
//        }
//        mTimeAdapter?.setNewData(list)
//        val handOrderBean = list?.firstOrNull()
//        handOrderBean?.isSelected = true
//        mTimeAdapter?.notifyDataSetChanged()
//        updateOrderInfo(handOrderBean)
//    }
//
//    interface OnGuaDanDialogListener {
//        fun onApplyOrder(handOrderBean: HandOrderBean)
//    }
}
